package work5;

import java.sql.*;

public class SqlConnection {
    private static String url = "jdbc:mysql://localhost:3306/work";
    private static String username = "root";
    private static String password = "1234";
    private static Statement stmt = null;
    private static ResultSet rs = null;
    private static Connection conn = null;

    static {
        // 加载数据库驱动程序
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            System.out.println("无法加载 MySQL 驱动程序");
            e.printStackTrace();

        }

        // 建立数据库连接
        try {
            conn = DriverManager.getConnection(url, username, password);
        } catch (SQLException e) {
            System.out.println("无法建立数据库连接");
            e.printStackTrace();

        }
    }



    public static Connection getConn(){
        return conn;
    }

}
